package cn.cloud.project.provder.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
@RequestMapping("/openApi")
public class OpenController {

    @Value("${server.port}")
    private String port;

    @GetMapping("/test")
    public String test(String id) {
        return "open feign 远程调用，id:" + id;
    }

    @GetMapping("/timeout")
    public String timeout() {
        try {
            TimeUnit.MINUTES.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "测试openfeign超时配置";
    }

    /**
     * 测试文件上传
     */
    @PostMapping(value = "/uploadImage", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String uploadImage(@RequestParam("file") MultipartFile file) {
        return file.getName();
    }

}
